const express = require("express")

const app = express()
const ERR1 = "err1"
const ERR2 = "err2"
app.post("/login", (req, res, next) => {
  next(new Error(ERR1))
})

app.post("/reg", (req, res, next) => {
  next(new Error(ERR2))
})


app.use((err, req, res, next) => {
  let status = 400
  let message = ""
  switch (err.message) {
  case ERR1:
    message = "err1"
    break;
  case ERR2:
    message = "err2"
    break;
  default:
    message = "not found"
  }

  res.status(status)
  res.json({
    code: status,
    message
  })

})


app.listen(8000, () => {
  console.log(" 服务器启动成功");
})